<?php
include('global.php');				//引入全局主文件
if(isset($_GET['action']) && $_GET['action'] == 'change')
{
	$GLOBALS['pos'] = '<a href="#" target="_self">修改个人资料</a>';
	$GLOBALS['title'] = '图书管理系统 - 修改个人资料';
	$page = 'change';
	$userinfo = $action->_get_userinfo($_GET['uid']);
}
else if(isset($_GET['action']) && $_GET['action'] == 'register')
{
	$GLOBALS['pos'] = '<a href="#" target="_self">注册新用户</a>';
	$GLOBALS['title'] = '图书管理系统 - 注册新用户';
	$page = 'register';
}
else
{
	$GLOBALS['pos'] = '<a href="login.php" target="_self">用户登录</a>';
	$GLOBALS['title'] = '图书管理系统 - 用户登录';
	$page = 'login'; 
}
if(isset($_POST['login_sub']))		//登录动作
{
	$query = sprintf("select * from `%s` where `userid`='%s' and `password`=sha1('%s')", 
					 PREFIX . 'reader', 
					 mysql_real_escape_string($_POST['username']), 
					 mysql_real_escape_string($_POST['password']));
	if($res = $mysql->_select($query))
	{
		$_SESSION['reader'] = $_POST['username'];	//登录成功
		$_SESSION['readerid'] = $res['id'];
		header('Location:index.php');
	}
	else
	{
		$mysql->msg('login.php', '用户名或密码错误！');
	}
}

if(isset($_POST['register_sub']))	//注册用户信息
{
	$action->_reg_user($_POST);		//注册动作
}

if(isset($_POST['edit_sub']))		//用户编辑个人资料
{
	$action->_edit_userinfo($_POST);
}
include('public/top.php');//引入头
switch($page)
{
	case 'login':
?>
<div class="login_page_style">
	<h3>登录</h3>
    <div class="login_page_info">图书管理系统欢迎您，请勿非法登录！</div>
    <table class="login_table">
    <form action="login.php" method="post">
    	<tr>
        	<td>用户名：</td>
        	<td><input type="text" class="inputtext" name="username"/></td>
        </tr>
    	<tr>
        	<td>密码：</td>
        	<td><input type="password" class="inputtext" name="password" /></td>
        </tr>
    	<tr>
        	<td>&nbsp;</td>
        	<td>
            <input type="submit" name="login_sub" class="login_btn2" value="登录" />
            <input type="reset" class="login_btn2" value="重置" />
            <a href="login.php?action=register">没有账号？注册一个</a>
            </td>
        </tr>
        </form>
    </table>
</div>
<div class="login_page_tishi">
	<div>
    <em class="login_page_close"><img src="style/image/close.gif" /></em>
    	<p>用户名或密码不能为空！</p>
	</div>
</div>
<?php
		break;
	case 'change':
?>
<div class="login_page_style">
	<h3>修改个人资料</h3>
    <form action="login.php" method="post">
    <dl class="edit_userinfo">
    <input type="hidden" name="uid" value="<?php echo $_GET['uid'];?>" />
    	<dd>用户名：<input type="text" class="inputtext" name="eusername" value="<?php echo isset($userinfo['username']) ? $userinfo['username'] : '';?>" /></dd>
        <dd>密码：（不修改请留空）<input type="password" class="inputtext" name="epwd1" /></dd>
        <dd>再次输入密码：（不修改请留空）<input type="password" class="inputtext" name="epwd2" /></dd>
    	<dd class="leftdd"> 性 别 ：
        <label><input type="radio" name="sex" value="男" <?php echo $userinfo['sex'] == '男' ? "checked='checked'" : '';?> />男</label>&nbsp;&nbsp;
        <label><input type="radio" name="sex" value="女" <?php echo $userinfo['sex'] == '女' ? "checked='checked'" : '';?> />女</label>&nbsp;&nbsp;
        <label><input type="radio" name="sex" value="保密" <?php echo $userinfo['sex'] == '保密' ? "checked='checked'" : '';?> />保密</label>&nbsp;&nbsp;
        </dd>
    	<dd>email：<input type="text" class="inputtext" name="eemail" value="<?php echo isset($userinfo['email']) ? $userinfo['email'] : '';?>" /></dd>
        <dd>
        <input type="submit" name="edit_sub" class="login_btn2" value="修改" />
        <input type="reset" class="login_btn2" value="重置" />
        <input type="button" onclick="history.go(-1)" class="login_btn2" value="返回" />
        </dd>
    </dl>
    </form>
</div>
<?php
		break;
	case 'register':
?>
<div class="login_page_style">
	<h3>注册新用户</h3>
    <form action="login.php" method="post">
    <dl class="edit_userinfo">
    	<dd>用户名：<input type="text" class="inputtext" name="ruserid"  /></dd>
    	<dd>密码：<input type="password" class="inputtext" name="rpwd1"  /></dd>
    	<dd>再次输入密码：<input type="password" class="inputtext" name="rpwd2"  /></dd>
        <dd>姓名：<input type="text" class="inputtext" name="rname"  /></dd>
    	<dd class="leftdd"> 性 别 ：
        <label><input type="radio" name="sex" value="男"  />男</label>&nbsp;&nbsp;
        <label><input type="radio" name="sex" value="女"  />女</label>&nbsp;&nbsp;
        <label><input type="radio" name="sex" value="保密" checked="checked" />保密</label>&nbsp;&nbsp;
        </dd>
    	<dd>email：<input type="text" class="inputtext" name="remail" /></dd>
        <dd>
        <input type="submit" name="register_sub" class="login_btn2" value="注册" />
        <input type="reset" class="login_btn2" value="重置" />
        <input type="button" onclick="history.go(-1)" class="login_btn2" value="返回" />
        </dd>
    </dl>
    </form>
</div>
<?php
		break;
}
echo $copyright;
?>
</body>
</html>